﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Logic.Packet
{
    public static class Paks
    {

        public static Dictionary<string, Type> ClientPaks;

        public static Dictionary<string, Type> ServerPaks;

        public static void FillClientPaks()
        {
            ClientPaks = new Dictionary<string, Type>();
            ClientPaks.Add("0001", typeof(CL_PlayerMove_N));
            ClientPaks.Add("0002", typeof(CL_PlayerMove_NE));
            ClientPaks.Add("0003", typeof(CL_PlayerMove_E));
            ClientPaks.Add("0004", typeof(CL_PlayerMove_SE));
            ClientPaks.Add("0005", typeof(CL_PlayerMove_S));
            ClientPaks.Add("0006", typeof(CL_PlayerMove_SW));
            ClientPaks.Add("0007", typeof(CL_PlayerMove_W));
            ClientPaks.Add("0008", typeof(CL_PlayerMove_NW));
            ClientPaks.Add("0009", typeof(CL_PlayerMove_Stop));
            ClientPaks.Add("0042", typeof(CL_MessageOfTheDay));
            ClientPaks.Add(string.Empty, typeof(ACK_Reply));
            ClientPaks.Add("000A", typeof(CL_KeepAlive));
            ClientPaks.Add("000B", typeof(CL_GetObject));
            //ClientPaks.Add("000C", CL_DepositObject);
            ClientPaks.Add("000E", typeof(CL_Login));
            ClientPaks.Add("005B", typeof(CL_PatchServerInformation));
            ClientPaks.Add("001B", typeof(CL_IndirectTalk));
            ClientPaks.Add("001C", typeof(CL_Shout));
            ClientPaks.Add("0031", typeof(CL_ChannelMessage));
            ClientPaks.Add("003E", typeof(CL_PersonalSpellList));
            ClientPaks.Add("0012", typeof(CL_BackpackItems));
            ClientPaks.Add("0013", typeof(CL_EquippedItems));
            ClientPaks.Add("0027", typeof(CL_PersonalSkills));
            ClientPaks.Add("002A", typeof(CL_UseSkill));
            ClientPaks.Add("002B", typeof(CL_PersonalStats));
            ClientPaks.Add("003B", typeof(CL_ItemName));
            ClientPaks.Add("006B", typeof(CL_DepositChest));
            ClientPaks.Add("0017", typeof(CL_UseObject));
            ClientPaks.Add("0015", typeof(CL_EquipObject));
            ClientPaks.Add("0016", typeof(CL_UnequipObject));
            ClientPaks.Add("0014", typeof(CL_ExitGame));
            ClientPaks.Add("0020", typeof(CL_CastSpell));
            ClientPaks.Add("0010", typeof(CL_SendPeriphericObjects));
            ClientPaks.Add("0048", typeof(CL_UseItemByAppearance));
            ClientPaks.Add("0018", typeof(CL_Attack));

        }
        public static void FillServerPaks()
        {
            ServerPaks = new Dictionary<string, Type>();
            ServerPaks.Add("0001", typeof(SRV_UpdateCoordinates));
            ServerPaks.Add("0009", typeof(SRV_SynchronizePlayerCoordinates));
            ServerPaks.Add("000A", typeof(SRV_KeepAlive));
            //ServerPaks.Add("000D", typeof(SRV_PutPlayerInGame));
            ServerPaks.Add("000E", typeof(SRV_Login));
            //ServerPaks.Add("000F", typeof(SRV_DeletePlayer));
            //ServerPaks.Add("000B", typeof(SRV_RemoveUnit));
            //ServerPaks.Add("000C", typeof(SRV_SetUnitAppearance));
            ServerPaks.Add("0042", typeof(SRV_MessageOfTheDay));
            ServerPaks.Add("0010", typeof(SRV_SendPeriphericObjects));
            ServerPaks.Add("0012", typeof(SRV_BackpackItems));
            //ServerPaks.Add("0013", typeof(SRV_EquippedItems));
            ServerPaks.Add("0014", typeof(SRV_ServerShutdown));
            //ServerPaks.Add("001A", typeof(SRV_PersonalPCList));
            ServerPaks.Add("001B", typeof(SRV_IndirectTalk));
            ServerPaks.Add("001D", typeof(SRV_Page));
            //ServerPaks.Add("001F", typeof(SRV_Reroll));
            ServerPaks.Add("0021", typeof(SRV_UpdateLife));
            //ServerPaks.Add("0022", typeof(SRV_BroadcastTextChange));
            //ServerPaks.Add("0023", typeof(SRV_UnitName));
            //ServerPaks.Add("0024", typeof(SRV_BreakConversation));
            //ServerPaks.Add("0025", typeof(SRV_UpdateLevel));
            //ServerPaks.Add("0026", typeof(SRV_ReturnToMenu));
            //ServerPaks.Add("0027", typeof(SRV_PersonalSkills));
            //ServerPaks.Add("0028", typeof(SRV_TrainList));
            //ServerPaks.Add("0029", typeof(SRV_BuyList));
            ServerPaks.Add("002B", typeof(SRV_PersonalStats));
            //ServerPaks.Add("002C", typeof(SRV_UpdateXP));
            //ServerPaks.Add("002D", typeof(SRV_UpdateTime));
            //ServerPaks.Add("002E", typeof(SRV_FromPreInGameToInGame));
            ServerPaks.Add("0031", typeof(SRV_ChannelMessage));
            //ServerPaks.Add("0032", typeof(SRV_ChannelUsers));
            //ServerPaks.Add("0033", typeof(SRV_PlayerList));
            //ServerPaks.Add("0035", typeof(SRV_UpdateGold));
            //ServerPaks.Add("0037", typeof(SRV_TeachList));
            //ServerPaks.Add("0038", typeof(SRV_SellList));
            ServerPaks.Add("0039", typeof(SRV_TeleportPlayer));
            ServerPaks.Add("003B", typeof(SRV_ItemName));
            //ServerPaks.Add("003C", typeof(SRV_NoUnitInView));
            //ServerPaks.Add("003E", typeof(SRV_PersonalSpellList));
            ServerPaks.Add("003F", typeof(SRV_ServerMessage));
            ServerPaks.Add("0040", typeof(SRV_CastingSpell));
            ServerPaks.Add("0041", typeof(SRV_ServerInformation));
            ServerPaks.Add("0043", typeof(SRV_UpdateMana));
            //ServerPaks.Add("0044", typeof(SRV_PuppetInformation));
            ServerPaks.Add("0045", typeof(SRV_UnitAppearance));
            //ServerPaks.Add("0046", typeof(SRV_UnitNotFound));
            ServerPaks.Add("0049", typeof(SRV_NoMoreItem));
            //ServerPaks.Add("004C", typeof(SRV_CreateGroup));
            //ServerPaks.Add("004E", typeof(SRV_GroupInvite));
            //ServerPaks.Add("0050", typeof(SRV_GroupLeave));
            //ServerPaks.Add("0052", typeof(SRV_DeleteGroup));
            ServerPaks.Add("0053", typeof(SRV_ActivateUserSpell));
            ServerPaks.Add("0054", typeof(SRV_SpellOff));
            //ServerPaks.Add("0058", typeof(SRV_ToggleGroupAutoSplit));
            //ServerPaks.Add("005A", typeof(SRV_PlayerExists));
            //ServerPaks.Add("005B", typeof(SRV_PatchServerInformation));
            //ServerPaks.Add("005D", typeof(SRV_Rob));
            //ServerPaks.Add("005E", typeof(SRV_DispelRob));
            ServerPaks.Add("005F", typeof(SRV_ArrowMissed));
            ServerPaks.Add("0060", typeof(SRV_ArrowSuccess));
            //ServerPaks.Add("0061", typeof(SRV_ServerFlags));
            //ServerPaks.Add("0062", typeof(SRV_SeraphArrival));
            //ServerPaks.Add("0063", typeof(SRV_AuthenticateVersion));
            //ServerPaks.Add("0064", typeof(SRV_ResetRegistryInventory));
            ServerPaks.Add("0065", typeof(SRV_InfoMessage));
            ServerPaks.Add("0067", typeof(SRV_MaxCharactersPerAccount));
            ServerPaks.Add("0068", typeof(SRV_ToggleWeather));
            ServerPaks.Add("0069", typeof(SRV_OpenURL));
            //ServerPaks.Add("006A", typeof(SRV_ChestItems));
            ServerPaks.Add("006D", typeof(SRV_OpenChest));
            ServerPaks.Add("006E", typeof(SRV_CloseChest));
            //ServerPaks.Add("0074", typeof(SRV_RequestExchange));
            //ServerPaks.Add("007A", typeof(SRV_ItemDescription));
            ServerPaks.Add("2711", typeof(SRV_AttackMissed));
            ServerPaks.Add("2712", typeof(SRV_AttackSuccess));
            ServerPaks.Add("2713", typeof(SRV_SkillSuccess));
            ServerPaks.Add("2714", typeof(SRV_PopupUnit));
            ServerPaks.Add(string.Empty, typeof(ACK_Reply));
        }

        public static void Init()
        {
            FillClientPaks();
            FillServerPaks();
        }

    }

    public class ACK_Reply : T4CBasePak
    {
        public ACK_Reply(T4CBasePak pak)
            : base(pak.Data)
        {
        }

        public override string Display()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(base.Display());
            sb.AppendFormat("ACK REPLY to PAK {0}", Id);
            sb.AppendLine();

            return sb.ToString();
        }
    }

    public class NotImplementedPak : T4CBasePak
    {
        public NotImplementedPak(T4CBasePak pak)
        {
            Data = pak.Data;
            ActionID = pak.ActionID;
            Signature = pak.Signature;
            Id = pak.Id;
        }

        public override string Display()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(base.Display());
            sb.AppendFormat("PAK {0} not implemented yet.", ActionID);
            sb.AppendLine();

            return sb.ToString();
        }
    }
}
